package sort;

import com.sun.org.apache.bcel.internal.generic.SWAP;

import java.util.ArrayList;
import java.util.List;

public class baseSort4QuickSort {
    public int getPatation(twoNodeMode[] list, int left, int right) {
        twoNodeMode myNode = list[right];
        int i = left - 1;
        for (int j = left; j < right; j++) {
            if (list[j].start < myNode.start || (list[j].start == myNode.start && list[j].end < myNode.end)) {
                i++;
                swap(list[i], list[j]);
            }
        }
        swap(list[i + 1], myNode);
        return i + 1;
    }

    private void swap(twoNodeMode o1, twoNodeMode o2) {
        int a = o1.start;
        int b = o1.end;
        o1.start = o2.start;
        o1.end = o2.end;
        o2.start = a;
        o2.end = b;
    }

    public void quickSort(twoNodeMode[] list, int left, int right) {
        if (left >= right) {
            return;
        }
        int p = getPatation(list, left, right);
        quickSort(list, left, p - 1);
        quickSort(list, p + 1, right);
    }

    public static void main(String[] args) {
        twoNodeMode[] array = {new twoNodeMode(1, 3), new twoNodeMode(2, 4), new twoNodeMode(3, 5),
                new twoNodeMode(2, 6), new twoNodeMode(4, 9)};
        baseSort4QuickSort sort = new baseSort4QuickSort();
        sort.quickSort(array, 0, array.length - 1);
        for (twoNodeMode node : array) {
            System.out.println(node.start + ":" + node.end);
        }
    }

}
